<?php
/**
 * Created by PhpStorm.
 * User: robot
 * Date: 2018-05-19
 * Time: 12:18
 */

namespace app\index\controller;



use app\base\BaseController;
use app\base\model\Books as BooksModel;
use app\base\model\Classify as fenlei;
use think\Request;


class Classify extends BaseController
{
    public function index()
    {
        $cid= $this->request->has('cid')?$this->request->param('cid'):'';
        $request = Request::instance();
        $books = new booksModel();
        $page = $request->has('page') ? $request->param('page') : 1;
        $limit = $request->has('limit') ? $request->param('limit') : 5;
        $offset = $limit * $page-$limit;
        $books_list = $books->where('classify_id','=',$cid)->limit($offset, $limit)->select();

        if($books_list) {
            $books_list = collection($books_list)->toArray();
        }

        $this->assign('books_count',$books->where('classify_id','=',$cid)->count('book_id'));
        $this->assign('limit',$limit);
        $this->assign('page',$page);
        $this->assign('classify_name', fenlei::get($cid)->name);
        $this->assign('books_list',$books_list);
        return $this->fetch();
    }

}